#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
const ll inf = 1e9 + 7;
#define speedup ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
namespace modop {
ll madd(ll a, ll b) {
return (a + b) % mod;
}
ll msub(ll a, ll b) {
return (((a - b) % mod) + mod) % mod;
}
ll mmul(ll a, ll b) {
return ((a % mod) * (b % mod)) % mod;
}
ll mpow(ll base, ll exp) {
ll res = 1;
while (exp) {
if (exp % 2 == 1) {
res = (res * base) % mod;
}
exp >>= 1;
base = (base * base) % mod;
}
return res;
}
ll minv(ll base) {
return mpow(base, mod - 2);
}
ll mdiv(ll a, ll b) {
return mmul(a, minv(b));
}
const ll FACTORIAL_SIZE = 1.1e6;
ll fact[FACTORIAL_SIZE], ifact[FACTORIAL_SIZE];
void gen_factorial(ll n) {
fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
for (ll i = 2; i <= n; i++) {
fact[i] = (i * fact[i - 1]) % mod;
}
ifact[n] = minv(fact[n]);
for (ll i = n - 1; i >= 2; i--) {
ifact[i] = ((i + 1) * ifact[i + 1]) % mod;
}
}
ll nck(ll n, ll k) {
if (k == 0) {
return 1;
}
ll den = (ifact[k] * ifact[n - k]) % mod;
return (den * fact[n]) % mod;
}
}
using namespace modop;
int main() {
gen_factorial(300005);
ll n;
cin >> n;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
ll ans = 1;
ll cc = 0;
for (int i = 1; i <= n; i += 3) {
cc++;
int val1 = v[i];
int val2 = v[i + 1];
int val3 = v[i + 2];
map<int, int> ct;
ct[val1]++;
ct[val2]++;
ct[val3]++;
if (ct.size() == 1) {
ans *= (3ll);
ans %= mod;
}
if (ct.size() == 2) {
auto it1 = *ct.begin();
auto it2 = *ct.rbegin();
int f = it1.second;
int s = it2.second;
if (s > f) {
ans *= (1ll);
ans %= mod;
}
else {
ans *= (2ll);
ans %= mod;
}
}
}
ll tomul = nck(cc, cc / 2);
ans = mmul(ans, tomul);
cout << ans << endl;
}
2085. Count Common Words With One Occurrence | 2089. Find Target Indices After Sorting Array |
2090. K Radius Subarray Averages | 2091. Removing Minimum and Maximum From Array |
6. Zigzag Conversion | 1612B - Special Permutation |
1481. Least Number of Unique Integers after K Removals | 1035. Uncrossed Lines |
328. Odd Even Linked List | 1219. Path with Maximum Gold |
1268. Search Suggestions System | 841. Keys and Rooms |
152. Maximum Product Subarray | 337. House Robber III |
869. Reordered Power of 2 | 1593C - Save More Mice |
1217. Minimum Cost to Move Chips to The Same Position | 347. Top K Frequent Elements |
1503. Last Moment Before All Ants Fall Out of a Plank | 430. Flatten a Multilevel Doubly Linked List |
1290. Convert Binary Number in a Linked List to Integer | 1525. Number of Good Ways to Split a String |
72. Edit Distance | 563. Binary Tree Tilt |
1306. Jump Game III | 236. Lowest Common Ancestor of a Binary Tree |
790. Domino and Tromino Tiling | 878. Nth Magical Number |
2099. Find Subsequence of Length K With the Largest Sum | 1608A - Find Array |